<?php
/**
 * Album
 *
 * Обработка данных по альбомам
 *
 * @author Дмитрий Кузьма <kouzma.d@gmail.com>
 * @version 1.0
 */
class Album extends ActiveRecord  {
	protected $tableName = 'album';
	public $pkName = 'ID_album';
	
	/**
	 * Получает список изображений с подмассивами файлов картинок
	 * 
	 *  @return array
	 */
	function getPhotos() {
	  Service_Debug::setDebug();
	  if (!$this->id) return array();
	  $objDB = Service_Database::instance();
	  $stmt = "SELECT `photo`.`ID_photo`, `photo`.`photo_name` 
	  FROM `photo` WHERE `photo`.`ID_album` = '" . $this->id . "'";
	  $arrPhotos = $objDB->select($stmt);
	  if ($arrPhotos) {
	  	$stmt = "SELECT `avatar`.`ID_essence` AS `ID_photo`, `avatar`.`avatar_alias`, `avatar`.`pic_file`, `avatar`.`pic_folder` 
		  FROM `avatar` 
		  WHERE 
		    `avatar`.`ID_essence` IN (" . join(',', Service_ArrayConverter::getColumn($arrPhotos, 'ID_photo')) . ")
		    AND `avatar`.`avatar_alias` IN ('small', 'big', 'very_big')
		  ";
		  $arrImages = $objDB->select($stmt);	
		  $arrPhotos = Service_ArrayConverter::combineArraysAndMakeKeys($arrPhotos, $arrImages, 'ID_photo', 'images', 'avatar_alias', true);
	  }
	  return $arrPhotos;
	}
}
?>